﻿using JESAI.Application.Abstractions.Dtos;
using JESAI.Application.Abstractions.Sys;
using JESAI.Application.Abstractions.Sys.Dtos;
using JESAI.Application.Abstractions.Sys.Querys;
using JESAI.AutoMapper.ObjectMapping;
using JESAI.Framework.Filters;
using JESAI.Framework.Mvc;
using JESAI.Platform.WebApi.Vos;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace JESAI.Platform.WebApi.Controllers
{
    [ApiController]
    [Route("api/v1/[controller]/[action]")]
    [Authorize("permission")]
    [IgnoreResultHandlerAttribute]
    public class FormController : ControllerBase
    {
        private readonly IFormService _formService;

        public FormController(IFormService formService)
        {
            _formService = formService;
        }

        [HttpGet]
        public async Task<BasePageOutput<List<FormResponse>>> GetFormPageList([FromQuery] FormPageQuery fromQuery)
        {
            var formPageList = await _formService.GetFormPageList(fromQuery);
            return formPageList.MapTo<BasePageOutput<List<FormResponse>>>();
        }

        [HttpPost]
        public async Task<BaseOutput> AddForm([FromBody] FormInput formInput)
        {
            await _formService.AddForm(formInput);
            return new BaseOutput();
        }

        [HttpPost]
        public async Task<BaseOutput> UpdateForm([FromBody] FormInput formInput)
        {
            await _formService.UpdateForm(formInput);
            return new BaseOutput();
        }

        [HttpGet]
        public async Task<BaseOutput> DelFormById(string formId)
        {
            await _formService.DelFormById(formId);
            return new BaseOutput();
        }

        [HttpGet]
        public async Task<BaseOutput> DelFormByIds(string[] formIds)
        {
            await _formService.DelFormByIds(formIds);
            return new BaseOutput();
        }

    }
}
